'''
Created on 29-Mar-2011
@description: Extracts student data from the EDULIX Info Bank profile 
              Located at (http://edulix.com/uploads/InfoBankReport.htm)
@author: Ashok
'''


from HTMLParser import HTMLParser
from xlwt import *
import copy


#Derived class. Has overloaded functions for HTML parsing
class infoBankParser(HTMLParser):
    studentDB = []
    sno = 0
    studId = 0
    def initialise(self):
        #Dictionary to store the students information
        #States                  Main State            Sub States            Dummy Value
        self.studentState   = { "Personal Info.:"   :{"Name:"               : "" ,
                                                      "Screenname:"         : ""},                                         
                                "Standard Tests:"   :{"GRE Quantitative:"   : "" ,
                                                      "GRE Verbal:"         : "" ,
                                                      "GRE Analytical/AWA:" : "" ,
                                                      "TOEFL:"              : ""},
                                "Acad. Info.:"      :{"UG College:"         : "" ,
                                                      "UG University:"      : "" ,
                                                      "UG Department:"      : "" ,
                                                      "UG Grade:"           : "" ,
                                                      "Addn. info:"         : "" , 
                                                      "Misc. info:"         : ""},
                                "Applications:"     :{"UnivInfo:"           : ""},
                                "Results:"          :{"Admits:"             : "" ,
                                                      "Rejects:"            : "" ,
                                                      "Waitlisted:"         : ""},
                                "Destination:"      :{"UnivInfo:"           : ""}}
        self.updateInfo      = False
        self.validMainState  = False
        self.validSubState   = False
        self.infoTypeIsList  = False
        self.sortedMainState = ["Personal Info.:",
                                "Standard Tests:",
                                "Acad. Info.:",
                                "Applications:",
                                "Results:",
                                "Destination:"]
        self.col_level_1 = ['ANNA UNIVERSITY, C.E.G',
                        'CEG',
                        'Coll of Engg., Guindy',
                        'College of Engg Guindy',
                        'College of Engg Guindy,',
                        'college of engg, guindy',
                        'college of engg.,guindy, chennai',
                        'college of engineering , guindy',
                        'College of Engineering , Guindy , Chennai',
                        'College of Engineering Guindy',
                        'College of Engineering Guindy Campus',
                        'College of Engineering Guindy,Anna University',
                        'College of Engineering, Guindy',
                        'College of Engineering, Guindy(CEG)',
                        'College of Engineering,Guindy',
                        'College of Engineering,Guindy(CEG)',
                        'College of Engineerng Guindy',
                        'College of Engneering, Guindy',
                        'College of Enigneering, Guindy']
        self.col_level_2 = ['Anna University (MIT Campus)',
                        'Madras Institue of Technology',
                        'Madras Institute of Tech',
                        'Madras Institute of Technology',
                        'Madras Institute Of Technology Campus',
                        'Madras Institute of Technology(MIT)',
                        'Madras Instt of Tech',
                        'Madras instutute of technology',
                        'MIT']
        self.col_level_3 = ['Birla Institue of Technology, Ranchi',
                        'Birla Institute of Technology',
                        'Birla Institute of Technology  and  Science, Pilani',
                        'Birla Institute of Technology and Scienc- Pilani',
                        'Birla Institute Of Technology and Science',
                        'Birla Institute of Technology and Science BITS, Pilani',
                        'Birla Institute of Technology and Science, Pilani',
                        'Birla Institute of Technology and Science, Pilani-Goa Campus',
                        'Birla Institute of Technology and Science,Pilani',
                        'BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCES, PILANI - DUBAI',
                        'BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCES,PILANI',
                        'Birla Institute of Technology Mesra Ranchi',
                        'Birla Institute of Technology, Ext. Centre, Jaipur',
                        'Birla Institute Of Technology, Mesra',
                        'Birla Institute of Technology, Ranchi',
                        'Birla Institute Of Technology,Mesra',
                        'Birla Institute of Technology,Mesra,Ranchi',
                        'BIT',
                        'BIT Mesra',
                        'BIT Mesra Ranchi',
                        'BIT Mesra, Ranchi',
                        'BIT,Mesra,Ranchi',
                        'BITS',
                        'BITS - Pilani',
                        'BITS - Pilani, Goa Campus',
                        'BITS Goa',
                        'BITS Pilani',
                        'bits pilani dubai',
                        'BITS Pilani Goa Campus',
                        'BITS Pilani -goa campus',
                        'BITS Pilani, Pilani Campus',
                        'BITS, pilani',
                        'BITS, Pilani - Dubai',
                        'BITS, Pilani (Pilani campus)',
                        'BITS, Pilani Goa Campus',
                        'BITS,Pilani',
                        'BITS_Pilani',
                        'BITS-Goa',
                        'BITS-Pilani',
                        'BITS-Pilani , Goa CAmpus',
                        'Bits-Pilani ,Goa Campus',
                        'BITS-Pilani Goa',
                        'BITS-Pilani Goa Campus',
                        'BITS-Pilani, Goa',
                        'Bits-Pilani, Goa Campus',
                        'BITS-Pilani,Goa campus',
                        'IIT B',
                        'IIT Bombay',
                        'IIT Guwahati',
                        'IIt Kanpur',
                        'IIT Kharagpur',
                        'IIT Madras',
                        'IIT Roorkee',
                        'IIT Roorkee, India',
                        'IIT, Kanpur',
                        'IITM',
                        'IIT-Roorkee',
                        'Indian Institute of Information Technology',
                        'Indian Institute of Information Technology , Allahabad',
                        'Indian Institute of Information Technology Allahabad',
                        'Indian Institute of Information Technology, Allahabad',
                        'Indian Institute of Information Technology,Allahabad',
                        'Indian Institute of Information Technology,Design  and  Manufacturing, Jabalpur',
                        'Indian Institute of Roorkee',
                        'Indian institute of technology',
                        'Indian Institute of Technology Guwahati',
                        'Indian Institute of Technology Roorkee',
                        'Indian Institute of Technology, Delhi',
                        'Indian Institute of Technology, Guwahati',
                        'Indian Institute of technology-Roorkee']

        #States of parseState
        self.STUDENTSTART    = 0
        self.STUDENTCONT     = 1
        self.STUDENTEND      = 2        
        
        
        #This variable to take one of the values of the Main state in the above table
        #It is initialised to 'Personal Info.:' because, that would indicate start of a new student 
        self.MainState       = "Personal Info.:"
        self.SubState        = ""
        self.prevMainState   = ""
        self.parseState      = self.STUDENTSTART   
        self.sheetNo         = 0           
#---------------------------------------------------------------------------------
    
    def handle_data(self, data):
        self.processData(data.strip())
#---------------------------------------------------------------------------------
    def handle_endtag(self, data):
        if data == "html":
            self.writeDataOfStudent()
            self.writeStudDBToFile()
            print 50*"-"
            print "PROCESSING COMPLETE"
            print 50*"-"
#---------------------------------------------------------------------------------    
    def handle_starttag(self, data, attr):
        if data == "table":
            #Only from a continue or end state we can go to start state
            if self.parseState != self.STUDENTSTART:                
                self.writeDataOfStudent()
                self.initialise()
        elif data == "h1" or data == "h2":
            #Only from a continue state, we can go to an end state
            if self.parseState != self.STUDENTSTART: 
                self.parseState = self.STUDENTEND     
#---------------------------------------------------------------------------------
    def processData(self, data):
        #We do not process data when the information pertaining to a student is complete
        if self.parseState != self.STUDENTEND:
            #------------------------------------
            #Check if we have got any valid data
            if data != "":
                #Check if we have a valid Main and Sub state
                if self.validMainState == True and self.validSubState == True:
                    self.updateInfo = True
                else:
                    self.updateInfo = False
            else:
                #Exit from the current cycle as the data got is NULL
                return 0
            #------------------------------------
            #See if the current data is Main State
            if data in self.studentState:
                self.prevMainState = self.MainState
                #We have encountered a 'Main State', So update it
                self.MainState = data
                #This Data contains state information. Info shall not be updated 
                self.validMainState = True
                #Do not update any information in this cycle as the data received is a 'Main State' data
                self.updateInfo = False
                #Check if there is a main state change.
                self.handleMainStateChange()          
            #See if the current data is a Sub State corresponding to this Main State
            elif self.MainState != "Applications:" and self.MainState != "Destination:":
                if data in self.studentState[self.MainState]:
                    self.SubState = data
                    #This Data contains state information. Info shall not be updated
                    self.validSubState = True
                    #We have found SubState information in this data. So don't update data to info
                    self.updateInfo = False
            #------------------------------------
            #Incoming data is neither a MainState not a SubState. It is normal data. So update it        
            if self.updateInfo == True:
                if self.infoTypeIsList == True:
                    self.studentState[self.MainState][self.SubState].append(data)                
                else:                    
                    #This is a normal data
                    self.studentState[self.MainState][self.SubState] = data            
#---------------------------------------------------------------------------------  
    def handleMainStateChange(self):
        #Main State has changed. Sub state for this main state is yet to be determined 
        self.validSubState = False
        self.infoTypeIsList = False
        self.parseState = self.STUDENTCONT
        #Check if the info is for 'Applications'. These are lists, and must be initialised
        if self.MainState == "Applications:":            
            self.SubState = "UnivInfo:"
            self.studentState[self.MainState][self.SubState] = []
            self.validSubState = True
            self.infoTypeIsList = True
        #Check if the info is for 'destination'. These are lists, and must be initialised
        elif self.MainState == "Destination:":
            self.SubState = "UnivInfo:"
            self.studentState[self.MainState][self.SubState] = []
            self.validSubState = True
            self.infoTypeIsList = True
        elif self.MainState == "Results:":
            for tempSubState in self.studentState[self.MainState]:
                self.studentState[self.MainState][tempSubState] = []
            self.infoTypeIsList = True             
#---------------------------------------------------------------------------------
    def writeDataOfStudent(self):        
        self.studId += 1        
        self.sno += 1
        if (self.studId % 86) == 0:
            self.percentComp +=1
            print self.percentComp, "%"
                        
        if self.curRow > 65530:
            self.infoBook.save(filePath + "UnivInfoBook.xls")
            print "Rows exceeded"
            exit(0)
          
#        print self.sno, self.studentState["Personal Info.:"]["Screenname:"]
        self.Col = 1        
        if self.studentState["Personal Info.:"]["Screenname:"] == 'dipika88':
            pass        
        self.writePersInfo(self.curRow)
        self.writeStdTest(self.curRow)
        self.writeUGInfo(self.curRow)
        self.writeAppInfo(self.curRow)
        self.writeResultInfo(self.curRow)
        self.writeDestInfo(self.curRow)
#        self.doFormatting(self.curRow)
        
        
        self.curRow += len(self.studentState["Applications:"]["UnivInfo:"])
    
    def writePersInfo(self, startRow):
    #startRow is the first empty row from which data of this student is to be filled        
        self.colOffset_Pers = self.startCol
        self.defStyle.num_format_str = '0'       
        for destRow in range(startRow, startRow + len(self.studentState["Applications:"]["UnivInfo:"])): 
            destCol = self.colOffset_Pers             
            self.infoSheet.row(destRow).write(destCol, self.studId, self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, self.studentState["Personal Info.:"]["Name:"], self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, self.studentState["Personal Info.:"]["Screenname:"], self.defStyle)
            destCol += 1            
        self.colOffset_Pers = destCol
        
    def writeStdTest(self, startRow):
        self.colOffset_StdTest = self.colOffset_Pers
        self.defStyle.num_format_str = '0'
        for destRow in range(startRow, startRow + len(self.studentState["Applications:"]["UnivInfo:"])):
            destCol = self.colOffset_StdTest 
            self.infoSheet.row(destRow).write(destCol, int(self.studentState["Standard Tests:"]["GRE Quantitative:"]), self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, int(self.studentState["Standard Tests:"]["GRE Verbal:"]), self.defStyle)
            destCol += 1
            #Some students have agre value as very high wrongly. e.g. 740. Inorder to suppress those 
            self.defStyle.num_format_str = '0.0'
            agre = float(self.studentState["Standard Tests:"]["GRE Analytical/AWA:"])
            if agre > 5.5:
                agre = 3
            self.infoSheet.row(destRow).write(destCol, agre, self.defStyle)
            destCol += 1
            self.defStyle.num_format_str = '0'
            self.infoSheet.row(destRow).write(destCol, int(self.studentState["Standard Tests:"]["TOEFL:"]), self.defStyle)
            destCol += 1
        self.colOffset_StdTest = destCol
        
    def writeUGInfo(self, startRow):
        self.colOffset_UGInfo = self.colOffset_StdTest
        for destRow in range(startRow, startRow + len(self.studentState["Applications:"]["UnivInfo:"])):
            destCol = self.colOffset_UGInfo
            self.defStyle.num_format_str = '0'
            self.infoSheet.row(destRow).write(destCol, self.detColLevel(), self.defStyle)
            destCol += 1 
            self.infoSheet.row(destRow).write(destCol, self.studentState["Acad. Info.:"]["UG College:"], self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, self.studentState["Acad. Info.:"]["UG University:"], self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, self.studentState["Acad. Info.:"]["UG Department:"], self.defStyle)
            destCol += 1
            #Separate grade information to actual grade and grade scale
            ugGrade = self.studentState["Acad. Info.:"]["UG Grade:"]
            ugGradeInfo = self.sepUgGrade(ugGrade)
            self.defStyle.num_format_str = '0.00'
            self.infoSheet.row(destRow).write(destCol, ugGradeInfo[0], self.defStyle)            
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, ugGradeInfo[1], self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, self.studentState["Acad. Info.:"]["Addn. info:"], self.defStyle)            
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, self.studentState["Acad. Info.:"]["Misc. info:"], self.defStyle)
            destCol += 1
        self.colOffset_UGInfo = destCol
        
    def writeAppInfo(self, startRow):
        self.colOffset_AppInfo = self.colOffset_UGInfo
        appNo = 0
        for destRow in range(startRow, startRow + len(self.studentState["Applications:"]["UnivInfo:"])):
            destCol = self.colOffset_UGInfo 
            #Separate the university information string in the input to separate meaningful
            #fields and update them                
            appUnivData = self.sepUnivInfo(appNo)
            self.infoSheet.row(destRow).write(destCol, appUnivData[0], self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, appUnivData[1], self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, appUnivData[2], self.defStyle)
            destCol += 1
            self.infoSheet.row(destRow).write(destCol, appUnivData[3], self.defStyle)
            destCol += 1
            appNo += 1           
        self.colOffset_AppInfo = destCol
            
    def writeResultInfo(self, startRow):
        self.colOffset_ResultInfo = self.colOffset_AppInfo
        resultNo = 0        
        resultInfo = ['','']
        for destRow in range(startRow, startRow + len(self.studentState["Results:"]["Admits:"])):
            destCol = self.colOffset_ResultInfo
            resultInfo = self.sepResultInfo(self.studentState["Results:"]["Admits:"][resultNo])
            newDestRow = self.detResultRow(resultInfo[0], startRow)
            if self.studentState["Results:"]["Admits:"][resultNo] != 'None':
                self.infoSheet.row(newDestRow).write(destCol, "Admit", self.defStyle)
                destCol += 1
                self.infoSheet.row(newDestRow).write(destCol, resultInfo[1], self.defStyle)
                destCol += 1
            resultNo += 1
            
        resultNo = 0
        for destRow in range(startRow, startRow + len(self.studentState["Results:"]["Rejects:"])): 
            destCol = self.colOffset_ResultInfo
            resultInfo = self.sepResultInfo(self.studentState["Results:"]["Rejects:"][resultNo])
            newDestRow = self.detResultRow(resultInfo[0], startRow)
            if self.studentState["Results:"]["Rejects:"][resultNo] != 'None':
                self.infoSheet.row(newDestRow).write(destCol, "Reject", self.defStyle)
                destCol += 1
                self.infoSheet.row(newDestRow).write(destCol, resultInfo[1], self.defStyle)
                destCol += 1
            resultNo += 1
        
        resultNo = 0
        for destRow in range(startRow, startRow + len(self.studentState["Results:"]["Waitlisted:"])): 
            destCol = self.colOffset_ResultInfo
            resultInfo = self.sepResultInfo(self.studentState["Results:"]["Waitlisted:"][resultNo])
            newDestRow = self.detResultRow(resultInfo[0], startRow)
            if self.studentState["Results:"]["Waitlisted:"][resultNo] != 'None':
                self.infoSheet.row(newDestRow).write(destCol, "Waitlisted", self.defStyle)
                destCol += 1
                self.infoSheet.row(newDestRow).write(destCol, resultInfo[1], self.defStyle)
                destCol += 1
            resultNo += 1            
        self.colOffset_ResultInfo = self.colOffset_AppInfo + 2

    def writeDestInfo(self, startRow):
        destCol = self.colOffset_ResultInfo
        destUniv = self.studentState["Destination:"]["UnivInfo:"][0].strip() 
        if destUniv != 'Not decided':
            newDestRow = self.detResultRow(destUniv, startRow)
            self.infoSheet.row(newDestRow).write(destCol, "Yes", self.defStyle)
             
#---------------------------------------------------------------------------------

    def doFormatting(self, startRow):
        tempStyle = copy.copy(self.defStyle)
        stuBorder = Borders()
        stuBorder.bottom = stuBorder.THICK
        stuBorder.bottom_colour = 0                
        tempStyle.borders = stuBorder
        startRow = startRow + len(self.studentState["Applications:"]["UnivInfo:"]) - 1
        self.infoSheet.row(startRow).set_style(tempStyle)     

    def sepUgGrade(self, ugGrdStr):
        firstSp = ugGrdStr.split('(', 1)
        grd = float(firstSp[0].strip())
        grdScale = firstSp[1].strip(' )')
        if grdScale == "%":
            grdThresh = 100
            grdAvg = 75
        elif grdScale == "10 point scale":
            grdThresh = 10
            grdAvg = 7.5            
        elif grdScale == "4 point scale":
            grdThresh = 4
            grdAvg = 3            
        elif grdScale == "5 point scale":
            grdThresh = 5
            grdAvg = 3.75            
        elif grdScale == "9 point scale":
            grdThresh = 9
            grdAvg = 6.75  
        else:
            grdThresh = 0
            grdAvg = 0
        if grd > grdThresh:
            grd = grdAvg
        elif grd == 0:
            grd = grdAvg
        firstSp[0] = grd
        firstSp[1] = grdScale
        return firstSp

    def detColLevel(self):
        col = self.studentState["Acad. Info.:"]["UG College:"].strip()
        if col in self.col_level_1:
            colLevel = 1
        elif col in self.col_level_2:
            colLevel = 2
        elif col in self.col_level_3:
            colLevel = 3
        else:
            colLevel = 10
        return colLevel
    
            

    def sepUnivInfo(self, appNo):
        univSpecData = []
        inStr = self.studentState["Applications:"]["UnivInfo:"][appNo]
        firstSp = inStr.split('.', 1)
        secSp   = firstSp[1].split('(', 1)
        univName = secSp[0].strip()
        thirdSp  = secSp[1].rsplit(',', 1)
        univYr   = thirdSp[1].strip(' )')
        if thirdSp[0].find('[') != -1:
            fourthSp = thirdSp[0].split('[',1)
            univDept = fourthSp[0].strip()
            univCourse = fourthSp[1].strip(' ]')
        else:
            univDept = thirdSp[0].strip()
            univCourse = ''
        univSpecData.append(univCourse)
        univSpecData.append(univDept)
        univSpecData.append(univYr)
        univSpecData.append(univName)                
        return univSpecData
    
    def sepResultInfo(self, resultStr):
        resultInfo = ['', '']
        if resultStr != 'None':
            firstSp = resultStr.split('.', 1)
            if firstSp[1].find('(') != -1:
                secSp = firstSp[1].split('(', 1)
                univName = secSp[0].strip()
                univComment =  secSp[1].strip(' )')
            else:
                univName = firstSp[1].strip()
                univComment = ''
            resultInfo[0] = univName
            resultInfo[1] = univComment
        return resultInfo
    
    def detResultRow(self, univName, destRow):
        if univName != '':
            for appUniv in self.studentState["Applications:"]["UnivInfo:"]:
                if appUniv.find(univName) != -1:
                    break                
                destRow += 1
        return destRow

    def initialiseWorkbook(self):                
        self.infoBook = Workbook(encoding='utf-8')
        self.addNewSheet()
        self.percentComp = 0
        
    def addNewSheet(self):
        self.sheetNo += 1
        self.infoSheet = self.infoBook.add_sheet("InfoSheet" + str(self.sheetNo), True)
        self.Col = 0
        #Column offsets for the fields to be written to the excel sheet
        self.startCol = 0
        self.curRow = 1
        destCol = 0
        colWidthFactor = 256
        #excel format table
        
        #Change the font style of the entire sheet
        font0 = Font()
        font0.name = 'Tahoma'
        font0.height = 160
        
        alignment0 = Alignment()
        alignment0.wrap = alignment0.WRAP_AT_RIGHT
        alignment0.vert = alignment0.VERT_TOP
        alignment0.horz = alignment0.HORZ_LEFT
                
        self.defStyle= XFStyle()
        self.defStyle.font = font0
        self.defStyle.alignment = alignment0
        
        
        headFont = Font()
        headFont.name = 'Tahoma'
        headFont.height = 200
        headFont.bold = True
        
        HeadStyle = XFStyle()
        HeadStyle.font = headFont
        
        self.infoSheet.panes_frozen = True
        self.infoSheet.horz_split_pos = 1
        self.infoSheet.row(0).write(destCol, "S.No", HeadStyle)
        self.infoSheet.col(destCol).width = 4 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Name:", HeadStyle)
        self.infoSheet.col(destCol).width = 15 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Screenname:", HeadStyle)
        self.infoSheet.col(destCol).width = 15 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "GRE-Q", HeadStyle)
        self.infoSheet.col(destCol).width = 4 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "GRE-V", HeadStyle)
        self.infoSheet.col(destCol).width = 4 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "GRE-A", HeadStyle)
        self.infoSheet.col(destCol).width = 4 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "TOEFL:", HeadStyle)
        self.infoSheet.col(destCol).width = 4 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Col Level", HeadStyle)
        self.infoSheet.col(destCol).Style = self.defStyle
        self.infoSheet.col(destCol).width = 4 * colWidthFactor
        destCol += 1
        self.infoSheet.row(0).write(destCol, "UG College:", HeadStyle)
        self.infoSheet.col(destCol).Style = self.defStyle
        self.infoSheet.col(destCol).width = 40 * colWidthFactor
        destCol += 1
        self.infoSheet.row(0).write(destCol, "UG University:", HeadStyle)
        self.infoSheet.col(destCol).width = 40 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "UG Department:", HeadStyle)
        self.infoSheet.col(destCol).width = 32 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "UG Grade:", HeadStyle)
        self.infoSheet.col(destCol).width = 6 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "UG Grade Scale:", HeadStyle)
        self.infoSheet.col(destCol).width = 10 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Addn. info:", HeadStyle)
        self.infoSheet.col(destCol).width = 50 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Misc. info:", HeadStyle)
        self.infoSheet.col(destCol).width = 50 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Applications:Applied Course", HeadStyle)
        self.infoSheet.col(destCol).width = 35 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Applications:Applied Degree", HeadStyle)
        self.infoSheet.col(destCol).width = 10 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Applications:Applied Year", HeadStyle)
        self.infoSheet.col(destCol).width = 9 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Applications:University", HeadStyle)
        self.infoSheet.col(destCol).width = 45 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Results", HeadStyle)
        self.infoSheet.col(destCol).width = 15 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Results Comment", HeadStyle)
        self.infoSheet.col(destCol).width = 50 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        self.infoSheet.row(0).write(destCol, "Destination:", HeadStyle)
        self.infoSheet.col(destCol).width = 50 * colWidthFactor
        self.infoSheet.col(destCol).Style = self.defStyle
        destCol += 1
        
    def writeStudDBToFile(self):
        self.infoBook.save(filePath + "InfoBook.xls")



#---------------------------------------------------------------------------------  
#            START OF PROGRAM
#---------------------------------------------------------------------------------  
filePath = "D:\NotSaved\elluswamy\uData\\"
fileName = "InfoBank Report.htm"
#fileName = "Small InfoBank Report.htm"
fileFullName = filePath + fileName 
infoBankObj = infoBankParser()
infoBankFile = open(fileFullName)
infoBankData = infoBankFile.read()
infoBankObj.initialise()
infoBankObj.initialiseWorkbook()
try:
    infoBankObj.feed(infoBankData)
except:
    infoBankObj.infoBook.save(filePath + "InfoBook.xls")
#print infoBankObj.studentState